package com.sense.kukoo.biz_media.adapter

import com.sense.kukoo.biz_media.adapter.provider.MediaChannelContentItemProvider
import com.sense.kukoo.biz_media.adapter.provider.MediaChannelEmptyItemProvider
import com.sense.kukoo.biz_media.adapter.provider.MediaChannelTitleProvider
import com.sense.kukoo.common.media.bean.LocalMediaListItemBean
import com.sense.kukoo.common.media.watcher.UserWatcher
import com.sense.kukoo.common.repo.biz.ChannelContentBean
import com.sense.kukoo.common.repo.http.bean.IndexContentBean
import com.sense.kukoo.common.repo.http.bean.UserInfoBean
import com.sense.kukoo.common.wiget.adapter.MultiItemAdapter

class MediaChannelAdapter(

    val data: List<ChannelContentBean>,
    val listener: IndexContentEventListener,

    ): MultiItemAdapter<ChannelContentBean>(data) {

    var mCurrentMusic: LocalMediaListItemBean? = null
    var mCurrentPlayState: Int = UserWatcher.MusicStateWatcher.STATE_NOT_PLAYING

    private val mMediaChannelTitleProvider = MediaChannelTitleProvider(listener)
    private val mMediaChannelContentItemProvider = MediaChannelContentItemProvider(listener)

    init {
        addItemProvider(mMediaChannelTitleProvider)
        addItemProvider(mMediaChannelContentItemProvider)
        addItemProvider(MediaChannelEmptyItemProvider())
    }

    override fun getItemType(data: MutableList<ChannelContentBean>, position: Int): Int {
        return data.get(position).type
    }

    fun setCurrentUserId(currentUserId:Long){
        mMediaChannelTitleProvider.setCurrentUserId(currentUserId)
    }

    interface IndexContentEventListener{
        fun onItemClick(data: IndexContentBean)
        fun onChannelClick(data: IndexContentBean)
        fun onBtnPlayClick(data: IndexContentBean)
        fun onFollowClick(data: UserInfoBean)
        fun onChannelUserIdClick(data: UserInfoBean)
    }

    fun setCurrentMusic(music: LocalMediaListItemBean){
        mCurrentMusic = music
        //
        mMediaChannelContentItemProvider.setCurrentMusic(music)
        notifyDataSetChanged()
    }

    fun setCurrentPlayState(state: Int){
        mCurrentPlayState = state
        //
        mMediaChannelContentItemProvider.setCurrentPlayState(state)
        notifyDataSetChanged()
    }

}